//
//  AppDelegate.m
//  QWView
//
//  Created by 李奇伟 on 15/3/28.
//  Copyright (c) 2015年 李奇伟. All rights reserved.
//

#import "QWView.h"
#import "UILabel+Additional.h"

@implementation QWView
-(void)dealloc
{
    [_imageView release];
    [_titleLabel release];
    [_contentLabel release];
    [super dealloc];
}
//左侧图片，右侧标题（图片的宽和高一致，中间以间距隔开，文本左对齐）
- (instancetype)initWithFrame:(CGRect)frame
                    leftImage:(NSString *)imageName
               titleLabeltext:(NSString *)titleText
                      Padding:(CGFloat)padding
{
    self = [super initWithFrame:frame];
    if ( self)
    {
        CGFloat totalWidth = frame.size.width;
        CGFloat totalHeight = frame.size.height;
        CGFloat imageWidth = totalHeight;
        CGFloat imageHeight = imageWidth;
        UIImage *image = [UIImage imageNamed:imageName];
        _imageView = [[UIImageView alloc] initWithImage:image];
        _imageView.frame = CGRectMake(0, 0, imageWidth, imageHeight);
        [self addSubview:_imageView];
        
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageWidth + padding, 0,totalWidth - imageWidth - padding, imageHeight) text:nil alignment:(NSTextAlignmentLeft)];//文本左面
        [self addSubview:_titleLabel];
        
    }
    return self;
}
//左侧图片，右侧标题（中间以间距隔开，左右文本以比例size体现）
- (instancetype)initWithFrame:(CGRect)frame
                    leftImage:(NSString *)imageName
               titleLabeltext:(NSString *)titleText
                      Padding:(CGFloat)padding
                         Size:(CGFloat)size
{
    self = [super initWithFrame:frame];
    if ( self)
    {
        CGFloat totalWidth = frame.size.width;
        CGFloat totalHeight = frame.size.height;
        CGFloat imageWidth = (totalWidth - padding) *size;
        CGFloat titleWidth = totalWidth - imageWidth - padding;
        UIImage *image = [UIImage imageNamed:imageName];
        _imageView = [[UIImageView alloc] initWithImage:image];
        _imageView.frame = CGRectMake(0, 0, imageWidth, totalHeight);
        [self addSubview:_imageView];
        
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageWidth + padding, 0,titleWidth, totalHeight) text:titleText alignment:(NSTextAlignmentLeft)];//文本左面
        [self addSubview:_titleLabel];
        
    }
    return self;
}
//左侧为图片，右侧上面为标题，下面为内容
- (instancetype)initWithFrame:(CGRect)frame
                    leftImage:(NSString *)imageName
             ImageOfLableSize:(CGFloat)imageSize
                      Padding:(CGFloat)padding
           titleOfSizeContent:(CGFloat)labelsize
{
    self = [super initWithFrame:frame];
    if ( self)
    {
        CGFloat totalWidth = frame.size.width;
        CGFloat totalHeight = frame.size.height;
        CGFloat imageWidth = (totalWidth - padding) *imageSize;
        
        CGFloat labelX = imageWidth +padding;
        CGFloat labelWidth = totalWidth - labelX;
        CGFloat titleHeight = (totalHeight - padding)*labelsize;
        CGFloat contentY = titleHeight + padding;
        CGFloat contentHeight = totalHeight - titleHeight - padding;
        
        UIImage *image = [UIImage imageNamed:imageName];
        _imageView = [[UIImageView alloc] initWithImage:image];
        _imageView.frame = CGRectMake(0, 0, imageWidth, totalHeight);
        [self addSubview:_imageView];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelX, 0, labelWidth, titleHeight)];
        [self addSubview:_titleLabel];
        
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelX, contentY, labelWidth, contentHeight )];
        [self addSubview:_contentLabel];
        
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
                   rightImage:(NSString *)imageName
             ImageOfLableSize:(CGFloat)imageSize
                      Padding:(CGFloat)padding
           titleOfSizeContent:(CGFloat)labelsize
{
    self = [super initWithFrame:frame];
    if ( self)
    {
        CGFloat totalWidth = frame.size.width;
        CGFloat totalHeight = frame.size.height;
        CGFloat imageWidth = (totalWidth - padding) *imageSize;
        
        CGFloat labelWidth = totalWidth - imageWidth - padding;
        CGFloat titleHeight = (totalHeight - padding)*labelsize;
        CGFloat contentY = titleHeight + padding;
        CGFloat contentHeight = totalHeight - titleHeight - padding;
        
        UIImage *image = [UIImage imageNamed:imageName];
        _imageView = [[UIImageView alloc] initWithImage:image];
        _imageView.frame = CGRectMake(totalWidth - imageWidth, 0, imageWidth, totalHeight);
        [self addSubview:_imageView];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, labelWidth, titleHeight)];
        [self addSubview:_titleLabel];
        
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, contentY, labelWidth, contentHeight )];
        [self addSubview:_contentLabel];
        
    }
    return self;
    
}
//上面为图片，下面为为标题，下面为内容

- (instancetype)initWithFrame:(CGRect)frame
                      upImage:(NSString *)imageName
             ImageOfLableSize:(CGFloat)imageSize
                      Padding:(CGFloat)padding
{
    self = [super initWithFrame:frame];
    if (self)
    {
        CGFloat totalWidth = frame.size.width;
        CGFloat totalHeight = frame.size.height;
        CGFloat imageHeight = totalHeight *imageSize;
        
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, totalWidth, imageHeight)];
        [self addSubview:_imageView];
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, imageHeight + padding, totalWidth, totalHeight - imageHeight - padding)];
        [self addSubview:_titleLabel];
    }
    return self;
}
#pragma  图片在上面，并且标题贴在图片上
- (instancetype)initWithFrame:(CGRect)frame
              titleAboveImage:(NSString *)imageName
             LabelOfImageSize:(CGFloat)labelSize
{
    self = [super initWithFrame:frame];
    if (self)
    {
        CGFloat totalWidth = frame.size.width;
        CGFloat totalHeight = frame.size.height;
        CGFloat labelHeight = totalHeight * labelSize;
        CGFloat labelY = totalHeight - labelHeight;
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, totalWidth, totalHeight)];
        [self addSubview:_imageView];
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,labelY, totalWidth, labelHeight)];
        [self.imageView addSubview:_titleLabel];
    }
    return self;
}



@end
